# coding=UTF-8
import time
import re
import uuid
import hashlib
import datetime
import logging
import execjs
import requests
import json
import base64,random
# from lxml import html
import jsonpath
# from w3lib import html
from random import choice
from numpy import int64, uint64
from w3lib.html import remove_tags,remove_tags_with_content
from parsel import Selector

def v_code(number):
    ret = ""
    for i in range(number):
        num = random.randint(0, 9)
        letter = chr(random.randint(97, 122))
        s = str(random.choice([num, letter]))
        ret += s
    return ret


def get_request_id():
    request_id = v_code(8) + '-' + v_code(4) + '-' + v_code(4) + '-' + v_code(4) + '-' + v_code(12)
    return str(request_id)


def get_device():
    device = ''.join(str(random.choice(range(12))) for _ in range(12))
    device = '86' + str(device)
    return device


def md5_hex(word):
    word = word.encode("utf-8")
    m = hashlib.md5()
    m.update(word)
    return str.upper(m.hexdigest())


def sha256_hex(word):
    word = word.encode("utf-8")
    word = hashlib.sha256(word).hexdigest()
    return word


def get_time():
    return int(time.time() * 1000)

class java_util:
    _R = 47
    _SEED = 19820125
    _M = int64(-4132994306676758123)
    _WBIT = _WINT64 = 8

    @classmethod
    def _bytes_convert_i64(cls, bytes):
        """
            change bytes arr to int64
        :param bytes: bytes arr as [1,2,3,4]
        :return:
        """
        ret = int64(0)
        for i, byte in enumerate(bytes):
            ret += byte << i * cls._WBIT
        return int64(ret)

    @classmethod
    def _unsigned_right_shift(cls, num, shift):
        """
            python unsigned right shift such as java >>>
        :param num:
        :param shift:
        :return:
        """
        return int(uint64(num)) >> shift

    @classmethod
    def _cal_factor_h(cls, key_len, transfer_bytes, h):
        h_i = key_len & 7
        for i in reversed(range(h_i)):
            h ^= int64(transfer_bytes[i] << i * cls._WBIT)
        return h * cls._M

    @classmethod
    def getIndentifier_64(cls, key):
        """
            reference java getIndentifier_64
        :param key:
        :return: id
        """
        bytes_array = [ord(elem) for elem in key]
        bytes_len = len(bytes_array)
        h = int64(cls._SEED ^ (bytes_len * cls._M))
        start, end = 0, int(bytes_len / cls._WBIT)

        while start != end:
            item_bytes = [0] * cls._WINT64
            i = start * cls._WBIT
            for j in range(cls._WINT64):
                item_bytes[j] = bytes_array[i + j]
            k = cls._bytes_convert_i64(item_bytes)
            k *= cls._M
            k ^= cls._unsigned_right_shift(k, cls._R)
            k *= cls._M
            h ^= k
            h *= cls._M
            start += 1

        transfer_bytes = [0] * cls._WINT64
        i, j = start * cls._WBIT, 0
        while i < bytes_len:
            transfer_bytes[j] = bytes_array[i]
            i += 1
            j += 1

        h = cls._cal_factor_h(bytes_len, transfer_bytes, h)

        h ^= cls._unsigned_right_shift(h, cls._R)
        h *= cls._M
        h ^= cls._unsigned_right_shift(h, cls._R)
        return h.item()


def is_number(s):
    """
    判断字符串是否为数字
    :param s:
    :return:
    """
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False


def analysis(content):
    """
    处理json中获取文本含tag，将其转换为html，xpath解析,保留img并保持img格式<br/><img src=...><br/><br/>
    :param content:
    :return:
    """
    result = remove_tags(content.replace('</p>','</p>\n'), keep=('img',))
    content = result.replace(">", "><br/><br/>\n").replace("<img", "<br/><img")
    return content

def analysis_xueqiu(content):
    """
    处理json中获取文本含tag，将其转换为html，xpath解析,保留img并保持img格式<br/><img ...><br/><br/>
    :param content:
    :return:
    """
    # etree = html.etree
    # a = urllib.parse.unquote(content)
    # html_content = etree.HTML(a)
    # content = ''.join(html_content.xpath("//text()"))
    # result = remove_tags(content, keep=('img',))
    result = remove_tags(content)
    content = result.replace(">", "><br/><br/>").replace("<img", "<br/><img")
    return content


def now_to_timestamp(digits=13):
    """
    获取时间戳，digits：10位和13位
    :param digits:
    :return:
    """
    time_stamp = time.time()
    digits = 10 ** (digits - 10)
    time_stamp = int(round(time_stamp * digits))
    return time_stamp


def timestamp_now_to(timeNum):
    """
    时间戳转换成时间
    :param timeNum:
    :return:
    """
    num = len(str(timeNum))
    timeNum = int(timeNum)
    if num == 13:
        timeStamp = float(timeNum / 1000)
        timeArray = time.localtime(timeStamp)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    else:
        otherStyleTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timeNum))
    return otherStyleTime


def re_data(String):
    """
    正则提取时间
    :param String:
    :return:
    """
    pattern = "\d+\.\d+\.d+ \d+:\d+"
    result = re.findall("\d+.\d+.\d+ \d+:\d+", String)
    return result


def get_zjol_headers(uri):
    """
    浙江新闻app解密,url的部分字符、uuid1、时间戳、固定字符，SHA256加密
    '/api/app_nav/list&&5d01c03db14e663f9275f26d&&d52d0a7e-81b6-46f4-8b44-db2136ea6284&&1560408819619&&XG?4VZ&4>9w'
    :param uri:
    :return:
    """
    uuid_str = str(uuid.uuid1())
    now_time = str(int(time.time() * 1000))
    decrypt_str = '{}&&5d01c03db14e663f9275f26d&&{}&&{}&&XG?4VZ&4>9w'.format(uri, uuid_str, now_time)
    x = hashlib.sha256()
    x.update(decrypt_str.encode())
    signture = x.hexdigest()
    headers = {
        'User-Agent': 'okhttp/3.11.0',
        'X-SESSION-ID': '5d01c03db14e663f9275f26d',
        'X-REQUEST-ID': '%s' % uuid_str,
        'X-TIMESTAMP': '%s' % now_time,
        'X-SIGNATURE': '%s' % signture,
    }
    return headers


def first_str_md5(string):
    """
    第一财经checkmd5加密
    :param string:
    :return:
    """
    str_m = string + 'aiB6Fkiusod0GMTp'
    m5 = hashlib.md5()
    m5.update(str_m.encode('utf-8'))
    m5_str = m5.hexdigest()
    return m5_str


def str_md5(string):
    """
    md5加密
    :param string:
    :return:
    """
    m5 = hashlib.md5()
    m5.update(string.encode('utf-8'))
    m5_str = m5.hexdigest()
    return m5_str.upper()

def get_img_urls(content):
    # image_url = get_img_urls(content)  image_url:list
    try:
        replace_pattern = r'<[img|IMG].*?/>'  # img标签的正则式
        img_url_pattern = r'.+?src=[\"\'](\S+)[\"\']'  # img_url的正则式
        need_replace_list = re.findall(replace_pattern, content)  # 找到所有的img标签
        img_url_list = []
        for tag in need_replace_list:
            img_url_list.append(re.findall(img_url_pattern, tag)[0])  # 找到所有的img_url
        # 对缺少http的url做处理
        if 'http' in img_url_list[0]:
            img_url_list = img_url_list
        elif '//' in img_url_list[0]:
            for i, v in enumerate(img_url_list): img_url_list[i] = ('https:' + v).replace('https:http', 'http:')
        else:
            img_url_list = img_url_list
        return img_url_list
    except Exception as e:
        # print(f'-----error_get_img_urls-----{e}')
        return []

def str_md5_dute(string, timstamp):
    """
    md5加密
    :param string:
    :return:
    """
    m5 = hashlib.md5()
    m5.update(string.encode('utf-8'))
    m5_str = m5.hexdigest()
    encryption = m5_str + "01ff984b3118a8ec815058f03025b6ac" + timstamp
    m5_1 = hashlib.md5()
    m5_1.update(encryption.encode('utf-8'))
    m5_encryption = m5_1.hexdigest()
    return m5_encryption


def get_urlid(url):
    """
    调用jar包计算urlid
    :param url:
    :return:
    """
    urlid = java_util.getIndentifier_64(url)
    return urlid


def gzrb_sign(time_now):
    """
    广州日报，md5加密，13位时间戳$123456
    """
    src = '{}$123456'.format(time_now)
    m5 = hashlib.md5()
    m5.update(src.encode())
    sign = m5.hexdigest()
    return sign


def xjb_sign(time_now):
    """
    新京报：
    1，CHANNEL_ID=1&PAGE=1&TIME=1563260593bjnews|lj345{@%^knw : 9221b559cef14de9441fcf56c663c919
    2，由1加密的结果截取30个字符然后再对其进行md5
    9221b559cef14de9441fcf56c663c9 : 2c0fd8c026d40a46a59a1c06a3ab439f
    :return:
    """
    src = "CHANNEL_ID=1&PAGE=1&TIME=" + str(time_now) + "bjnews|lj345{@%^knw"
    m5 = hashlib.md5()
    m5.update(src.encode())
    sign1 = m5.hexdigest()
    src1 = sign1[0:30]
    m5 = hashlib.md5()
    m5.update(src1.encode())
    sign = m5.hexdigest()
    return sign


def get_time(pubtime):
    """
    用于修改时间：当年时间不显示年份，往年时间有年份
    :param pubtime:
    :return:
    """
    pattern1 = "\d+-\d+ \d+:\d+"
    time_test = re.match(pattern1, pubtime)
    year = datetime.datetime.now().year
    if time_test:
        time_now = (str(year) + "-" + pubtime + ":00")
    else:
        time_now = pubtime
    return time_now


def get_pubtime(time_str):
    """
    n天前、n小时前、n分钟前、昨天 00：00、前天00：00，根据当前时间减去对应时间
    :param time_str:
    :return:
    """
    try:
        pattern1 = "\d+-\d+ \d+:\d+"
        pattern2 = "\d+-\d+"
        pattern3 = "前天 (\d+:\d+)"
        pattern4 = "昨天 (\d+:\d+)"
        pattern5 = "(\d+)月(\d+)日"
        pattern6 = "(\d+)-(\d+)-(\d+)"
        time_test = re.match(pattern1, time_str)
        time_test1 = re.match(pattern2, time_str)
        time_test2 = re.match(pattern3, time_str)
        time_test3 = re.match(pattern4, time_str)
        time_test4 = re.match(pattern5, time_str)
        time_test5 = re.match(pattern6, time_str)
        year = datetime.datetime.now().year
        if time_test:
            pubtime = (str(year) + "-" + time_str)
        elif time_test1:
            pubtime = datetime.datetime.strptime(str(year) + "-" + time_str + " 00:00:00", "%Y-%m-%d %H:%M:%S")
        elif time_test2:
            day_time = 2
            hour_m = time_test2.group(1)
            days = (datetime.datetime.now() + datetime.timedelta(days=-int(day_time))).strftime("%Y-%m-%d")
            pubtime = datetime.datetime.strptime(str(days) + " " + hour_m, "%Y-%m-%d %H:%M")
        elif time_test3:
            day_time = 1
            hour_m = time_test3.group(1)
            days = (datetime.datetime.now() + datetime.timedelta(days=-int(day_time))).strftime("%Y-%m-%d")
            pubtime = datetime.datetime.strptime(str(days) + " " + hour_m, "%Y-%m-%d %H:%M")
        elif time_test4:
            months = time_test4.group(1)
            days = time_test4.group(2)
            y = datetime.datetime.now().year
            b = (str(y) + "-" + str(months) + "-" + str(days))
            pubtime = datetime.datetime.strptime(str(b), "%Y-%m-%d")
        elif "昨天" in time_str:
            day_time = 1
            pubtime = (datetime.datetime.now() + datetime.timedelta(days=-int(day_time))).strftime("%Y-%m-%d %H:%M:%S")
        elif "前天" in time_str:
            day_time = 2
            pubtime = (datetime.datetime.now() + datetime.timedelta(days=-int(day_time))).strftime("%Y-%m-%d %H:%M:%S")
        elif "天" in time_str:
            day_time = re.search("\d+", time_str).group()
            pubtime = (datetime.datetime.now() + datetime.timedelta(days=-int(day_time))).strftime("%Y-%m-%d %H:%M:%S")
        elif "时" in time_str:
            hours_time = re.search("\d+", time_str).group()
            pubtime = (datetime.datetime.now() + datetime.timedelta(hours=-int(hours_time))).strftime("%Y-%m-%d %H:%M:%S")
        elif "分" in time_str:
            minutes_time = re.search("\d+", time_str).group()
            pubtime = (datetime.datetime.now() + datetime.timedelta(minutes=-int(minutes_time))).strftime("%Y-%m-%d %H:%M:%S")
        else:
            pubtime = time_str
        return str(pubtime)
    except Exception as e:
        logging.info("utils get_pubtime error %s" % e)


def jhdnews_content(content):
    """
    处理交汇点新闻APP正文中的 img、input
    :param content:
    :return:
    """
    img_data = remove_tags(content, keep=('img',))
    img_url = re.findall('imageurl="(.*?)"', content)
    for i in range(len(img_url)):
        newtag = '<br/><img src="%s" /><br /><br />' % img_url[i]
        img_data = re.sub(r'<img src="" style=.*?imageid=.*?>', newtag, img_data, count=1)
    return img_data


def uc_content_img(content, img_list):
    """
    UC头条APP正文中的 <!--{img:\d+}-->
    :param content:
    :return:
    """
    # img_data = html.remove_tags(content, keep=('img',))
    for img_url in img_list:
        newtag = '<br/><img src="%s" /><br /><br />' % img_url
        content = re.sub(r'<!--{img:\d+}-->', newtag, content, count=1)
    img_data = html.remove_tags(content, keep=('img',))
    content = img_data.replace(">", "><br/><br/>").replace("<img", "<br/><img")
    return content


def sina_content_img(content, img_list):
    """
    UC头条APP正文中的 <!--{img:\d+}-->
    :param content:
    :return:
    """
    # img_data = html.remove_tags(content, keep=('img',))
    for img_url in img_list:
        newtag = '<br/><img src="%s" /><br /><br />' % img_url
        content = re.sub(r'<!--{IMG_\d+}-->', newtag, content, count=1)
    img_data = html.remove_tags(content, keep=('img',))
    content = img_data.replace(">", "><br/><br/>").replace("<img", "<br/><img")
    return content


def get_xrdz_md5(str_time):
    md_str = str_time + "xinrui@#$%^"
    m5 = hashlib.md5()
    m5.update(md_str.encode('utf8'))
    sign = m5.hexdigest()
    return sign


def uc_content_img(content, img_list):
    """
    UC头条APP正文中的 <!--{img:\d+}-->
    :param content:
    :return:
    """
    # img_data = html.remove_tags(content, keep=('img',))

    for img_url in img_list:
        newtag = '<br/><img src="%s" /><br /><br />' % img_url
        content = re.sub(r'<!--IMAGEARRAY#\d+-->', newtag, content, count=1)
    img_data = remove_tags(content, keep=('img',))
    content = img_data.replace(">", "><br/><br/>").replace("<img", "<br/><img")
    return content


def content_img_163(content, img_list):
    """
    UC头条APP正文中的 <!--{img:\d+}-->
    :param content:
    :return:
    """
    # img_data = html.remove_tags(content, keep=('img',))

    for img_url in img_list:
        newtag = '<br/><img src="%s" /><br /><br />' % img_url
        content = re.sub(r'<!--IMG#\d+-->', newtag, content, count=1)
    img_data = remove_tags(content, keep=('img',))
    content = img_data.replace(">", "><br/><br/>").replace("<img", "<br/><img")
    return content


def minhang_content_img(content, img_list):
    """
    UC头条APP正文中的 <!--{img:\d+}-->
    :param content:
    :return:
    """
    # img_data = html.remove_tags(content, keep=('img',))

    for img_url in img_list:
        newtag = '<br/><img src="%s" /><br /><br />' % img_url
        content = re.sub(r'<!--IMG#\d+-->', newtag, content, count=1)
    img_data = html.remove_tags(content, keep=('img',))
    content = img_data.replace(">", "><br/><br/>").replace("<img", "<br/><img")
    return content

import re, requests, json, time, jsonpath
from lxml import etree, html
def get_headers(_method, _url, _body):
    with open('demo_wxapp_midoubaoliao.js', encoding='utf-8-sig') as f:
        js_string = f.read()
    js = execjs.compile(js_string)
    return js.call("getHeaders", _method, _url, _body)


def get_lsign(chanel_name, timestamp, rand):
    """
    新浪list加密
    :param chanel_name:频道名称
    :param timestamp:十位时间戳
    :param rand:随机3位数
    :return:
    """
    url = "http://172.31.97.136:9206/sina_news_url_sign"
    timestamp = "1575425740"
    data = {
        "url": "/?resource=feed&mpName=%E6%8E%A8%E8%8D%90&lDid=b24a56a9-659f-43e7-a513-d6aee755638d&appVersion=7.27.0&oldChwm=12606_0020&upTimes=0&city=&loginType=0&authToken=&channel="
               "{}&link=&authGuid=&open_adtype=0&ua=samsung-SM-G9008V__sinanews__7.27.0__android__6.0.1__460&deviceId=5fe4bf43f0f92ced&connectionType=2&resolution=1080x1920&mac=02%3A00%3A00%3A00%3A00%3A00&weiboUid=&replacedFlag=1&ssoVer=3&osVersion=6.0.1&chwm=12606_0020&pullTimes=9&weiboSuid=&andId=72778638eef7748b&from=6000095012&sn=758f9a95&behavior=manual&aId=01A7okPXIARdQOESumGa1ip_EnttI9naBuQ4GcUiapDzePXhA.&topStyle=z&oaid=&localSign=a_f39c80a5-d193-4979-a4c7-f2ccc18579ee&deviceIdV1=bed114f3cec75d77&osSdk=23&listCount=17&accessToken=&downTimes=8&sand=20C87XZV7Wdr%2BEpSz9s7lQ%3D%3D"
               "&lastTimestamp={}&pullDirection=down&seId=9f4b48ed79&imei=&deviceModel=samsung__samsung__SM-G9008V&location=0.0%2C0.0&"
               "authUid=&loadingAdTimestamp=0_{}".format(chanel_name, timestamp, rand)
    }
    url_join = (data['url'])
    data = requests.post(url=url, data=json.dumps(data))
    sign = (re.search('"urlSign":"(\w+)"', data.text).group(1))
    list_url = url_join[:-4]
    headers = {
        "rand": "%s" % rand,
        "urlSign": "%s" % sign,
    }
    return headers


def get_lsign(chanel_name, timestamp, rand):
    """
    新浪list加密
    :param chanel_name:频道名称
    :param timestamp:十位时间戳
    :param rand:随机3位数
    :return:
    """
    url = "http://172.31.97.136:9206/sina_news_url_sign"
    data = {
        "url": "/?resource=feed&mpName=%E6%8E%A8%E8%8D%90&lDid=b24a56a9-659f-43e7-a513-d6aee755638d&appVersion=7.27.0&oldChwm=12606_0020&upTimes=0&city=&loginType=0&authToken=&channel="
               "{}&link=&authGuid=&open_adtype=0&ua=samsung-SM-G9008V__sinanews__7.27.0__android__6.0.1__460&deviceId=5fe4bf43f0f92ced&connectionType=2&resolution=1080x1920&mac=02%3A00%3A00%3A00%3A00%3A00&weiboUid=&replacedFlag=1&ssoVer=3&osVersion=6.0.1&chwm=12606_0020&pullTimes=9&weiboSuid=&andId=72778638eef7748b&from=6000095012&sn=758f9a95&behavior=manual&aId=01A7okPXIARdQOESumGa1ip_EnttI9naBuQ4GcUiapDzePXhA.&topStyle=z&oaid=&localSign=a_f39c80a5-d193-4979-a4c7-f2ccc18579ee&deviceIdV1=bed114f3cec75d77&osSdk=23&listCount=17&accessToken=&downTimes=8&sand=20C87XZV7Wdr%2BEpSz9s7lQ%3D%3D"
               "&lastTimestamp={}&pullDirection=down&seId=9f4b48ed79&imei=&deviceModel=samsung__samsung__SM-G9008V&location=0.0%2C0.0&"
               "authUid=&loadingAdTimestamp=0_{}".format(chanel_name, timestamp, rand)
    }
    result = requests.post(url=url, data=json.dumps(data))
    sign = (re.search('"urlSign":"(\w+)"', result.text).group(1))
    url_join = data['url']
    list_url = url_join[:-4]
    return list_url, rand, sign


def get_asign(news_id, rand):
    """
    新浪list加密
    :param news_id:频道名称
    :param timestamp:十位时间戳
    :param rand:随机3位数
    :return:
    """
    url = "http://172.31.97.136:9206/sina_news_url_sign"
    data = {
        "url": "/?resource=article&lDid=83ee0d33-5d4c-433d-be9a-9e9b894f4670&appVersion=7.27.0&oldChwm=12606_0020&city=CN11010500000000&loginType=0"
               "&authToken=&link=http%3A%2F%2Fsports.sina.cn%2Flaliga%2Frealmadrid%2F2019-12-04%2Fdetail-iihnzhfz3567211.d.html%3Fcre%3Dtianyi%26mod%3Dnspt%26loc%3D1%26r%3D27%26rfunc%3D6%26tj%3Dcxvertical_nspt%26tr%3D27%26fromsinago%3D1"
               "&authGuid=&postt=news_news_sports_preload_null&ua=OnePlus-ONEPLUS+A5010__sinanews__7.27.0__android__7.1.1__460&deviceId=1bc14f6837d63e25&connectionType=2"
               "&resolution=1080x2034&mac=02%3A00%3A00%3A00%3A00%3A00&weiboUid=&ssoVer=3&osVersion=7.1.1&chwm=14170_0001&weiboSuid=&andId=2f01e70e91225122"
               "&from=6000095012&sn=280d06ad&aId=01A2vfNdfUqk0AE2LrbUQoQgiSDxIWnvy_UZe1cLDKIRDslO0.&oaid=&deviceIdV1=1bc14f6837d63e25&osSdk=25&accessToken="
               "&sand=RNylipf%2B%2FZhX2Vqj1VESCUdaJAHOnmQ9Vkhpj9ny7qI%3D&newsId={}&dataid=comos%3Aihnzhfz3567211&seId=367fe93304"
               "&imei=99001079028007&deviceModel=OnePlus__OnePlus__ONEPLUS+A5010&location=39.919417%2C116.470198&authUid=_{}".format(news_id, rand)
    }
    result = requests.post(url=url, data=json.dumps(data))
    sign = (re.search('"urlSign":"(\w+)"', result.text).group(1))
    url_join = (data['url'])
    list_url = url_join[:-4]
    return list_url, rand, sign


def decryptCode(code):
    b = ""
    for i in range(len(code)):
        c = code[i]
        if c == 'A':
            c = 'Z'
        elif c == 'a':
            c = 'z'
        elif c == '0':
            c = '9'
        elif ('A' < c and c <= 'Z') or (('a' < c and c <= 'z') or ('0' < c and c <= '9')):
            c = chr(ord(c) - 1)
        b += c
    return base64.b64decode(b).decode()


def qq_finance_sign():
    nonce = ("".join([choice("0123456789") for i in range(4)]))
    zaapid = "zxg_h5"
    password = '9c8e247b438b7d0ae845f9931810a387'
    src = zaapid + password + nonce
    m5 = hashlib.md5()
    m5.update(src.encode())
    sign = m5.hexdigest()
    data = "&zappid=zxg_h5&sign={}&nonce={}".format(sign, nonce)
    return data


def get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="thread_subject"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="shareVideo_title"]/text()')
    return title


def photo_and_text(xpath_list):
    text = ""
    for i in xpath_list:
        path = html.tostring(i, encoding='utf-8').decode('utf-8')
        if 'img' in path:
            img = i.xpath('.//br//img/@src')
            img = img + i.xpath('.//@src')
            if img and img[0] not in text:
                if 'http' not in img[0]:
                    text = text + '<br/><img src="http:{}" /><br /><br />'.format(img[0])
                else:
                    text = text + '<br/><img src="{}" /><br /><br />'.format(img[0])
        else:
            # print(path)
            content = i.xpath('.//text()')
            content = content + i.xpath('.//section/p//text()')
            if content and content[0] not in text:
                text = text + content[0]
    return text


def get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="t_f"]//*')
        if not content:
            content = selector.xpath('//*[@class="text"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


# def get_pubtime(text):
#     if not text:
#         return ""
#     else:
#         selector = etree.HTML(text)
#         pubtime = selector.xpath('//*//em/span//text()')
#         if pubtime:
#             pubtime = pubtime[0]
#             pubtime = timestamp_now_to(pubtime)
#         else:
#             pubtime = selector.xpath('//*[@class="authi"]//em//text()')[0]
#             pubtime = pubtime.split(" ")[1]
#             pubtime = timestamp_now_to(pubtime)
#         return pubtime


def get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


# def timestamp_now_to(timeNum):
#     """
#     时间戳转换成时间
#     :param timeNum:
#     :return:
#     """
#     timeNum = str(timeNum)
#     if '分钟前' in timeNum:
#         timeNum = timeNum.replace("分钟前", "")
#         timeNum = str((int(time.time())) - int(timeNum) * 60)
#     if '小时前' in timeNum:
#         timeNum = timeNum.replace("小时前", "")
#         timeNum = str((int(time.time())) - int(timeNum) * 60 * 60)
#     if '昨天' in timeNum:
#         timeNum = str((int(time.time())) - 24 * 60 * 60)
#     if '前天' in timeNum:
#         timeNum = str((int(time.time())) - 2 * 24 * 60 * 60)
#     if '天前' in timeNum:
#         timeNum = timeNum.replace("天前", "")
#         timeNum = str((int(time.time())) - int(timeNum) * 24 * 60 * 60)
#     pat = '-(\d{1}).+?'
#     tt = re.compile(pat).findall(timeNum)
#     if tt:
#         for e in tt:
#             a = '-{}-'.format(e)
#             b = '-0{}-'.format(e)
#             timeNum = re.sub(a, b, timeNum)
#
#     t = re.compile("(\d)").findall(str(timeNum))
#     timeNum = ""
#     for e in t:
#         timeNum = timeNum + str(e)
#     num = len(str(timeNum))
#     timeNum = int(timeNum)
#     if num == 13:
#         timeStamp = float(timeNum / 1000)
#         timeArray = time.localtime(timeStamp)
#         otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
#     elif num == 10:
#         otherStyleTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timeNum))
#     else:
#         otherStyleTime = str(timeNum)
#         for e in range(14 - len(str(timeNum))):
#             otherStyleTime = otherStyleTime + "0"
#         pubtime = otherStyleTime[0:4] + "-" + otherStyleTime[4:6] + "-" + otherStyleTime[6:8] + " " + otherStyleTime[8:10] + ":" + otherStyleTime[
#                                                                                                                                    10:12] + ":" + otherStyleTime[
#                                                                                                                                                   12:14]
#         otherStyleTime = pubtime
#     return otherStyleTime


def jxxw_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="data"]/text()')
        if pubtime:
            pubtime = pubtime.split(" |")[0]
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')[0]
        return pubtime


def jxxw_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def jxxw_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="main"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def cgivoc_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@id="time"]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')
            if pubtime:
                pubtime = pubtime[0]
                pubtime = timestamp_now_to(pubtime)
        if isinstance(pubtime, str):
            return pubtime
        return None


def cgivoc_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="main_title"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def cgivoc_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="id="s0""]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def cgivoc_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="content"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def wenge_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="dabiaoti"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def wenge_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="Content"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def wenge_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@id="pubtime"]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')[0]
        return pubtime


def rednet_get_content(text):
    selector = etree.HTML(text)
    content = selector.xpath('//*[@class="description"]//*')
    if not content:
        content = selector.xpath('//*[@id="js_content"]//*')
    content = photo_and_text(content)
    content_text = ""
    for e in content:
        content_text = content_text + e
    content_text = content_text.replace('\r', '')
    content_text = content_text.replace('\n', '')
    content_text = content_text.replace('\t', '')
    content_text = content_text.replace('\xa0', '')
    content_text = content_text.replace('\u3000', '')
    return content_text


def rednet_get_pubtime(text):
    pat = ' n="(.*?)"'
    pubtime = re.compile(pat).findall(text)
    if pubtime:
        pubtime = timestamp_now_to(pubtime[0])
        return pubtime
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="data"]/text()')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')
            pubtime = timestamp_now_to(pubtime[0])
        return pubtime


def rednet_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="rich_media_title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def nj025_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//div[@class="about"]//span[1]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')[0]
        return pubtime


def nj025_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def nj025_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="about"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def nj025_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="about"]/h1/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def qichezhuanye_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="theme-brief"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def shanbay_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="text"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def i2863_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="authorTt"]/span[2]/text()')
        if not author:
            author = ""
        return author


def i2863_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('/html/body//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def lsrm_get_pubtime(text):
    text = str(text)
    if not text:
        return ""
    else:
        selector = Selector(text=text)
        pubtime = selector.xpath('//*[@class="hender-info-over"]/span[0]/text()')
        pubtime = text
        if pubtime:
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="article-time"]/text()')[0]
        return pubtime


def lsrm_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="theme-brief"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def zhoushan_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="time"]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="shareVideo_time"]/text()')[0]
            pubtime = pubtime.split(" |")[0]
            pubtime = timestamp_now_to(pubtime)
        return pubtime


def zhoushan_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def zhoushan_photo_and_text(xpath_list, u):
    text = ""
    for i in xpath_list:
        path = html.tostring(i, encoding='utf-8').decode('utf-8')
        if 'img' in path:
            img = i.xpath('.//br//img/@src')
            img = img + i.xpath('.//@src')
            if img:
                if 'http' not in img[0]:
                    text = text + '<br/><img src="{}{}" /><br /><br />'.format(u, img[0]).replace("./", "/")

                else:
                    text = text + '<br/><img src="{}" /><br /><br />'.format(img[0])
        else:
            # print(path)
            content = i.xpath('.//text()')
            # content = content + i.xpath('.//span/text()')
            if content:
                text = text + content[0]
    return text


def zhoushan_get_content(text, u):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="TRS_Editor"]//*')
        if not content:
            content = selector.xpath('//*[@class="text"]//*')
        content = zhoushan_photo_and_text(content, u)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
        content_text = re.sub('\.TRS.*?ht:2;\}', "", content_text)
    else:
        content_text = ""
    return content_text


def zhoushan_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="title"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="shareVideo_title"]/text()')[0]
    return title


def hebyun_get_pubtime(text):
    try:
        if not text:
            return ""
        else:
            selector = etree.HTML(text)
            pubtime = selector.xpath('//*[@class="hender-info-over"]/span[0]/text()')
            if pubtime:
                pubtime = timestamp_now_to(pubtime[0])
            else:
                pubtime = selector.xpath('//*[@class="article-time"]/text()')[0]
    except Exception as exc:
        pubtime = ""
    return pubtime


def hebyun_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="f15a"]/text()')
        if not author:
            author = ""
        else:
            author = author[0]
        return author


def hebyun_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="articleContent"]//*')
        if not content:
            content = selector.xpath('//*[@class="theme-brief"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def hebyun_get_title(text):
    selector = etree.HTML(text)
    try:
        title = selector.xpath('//*[@class="article-title"]/text()')
        if title:
            title = title[0]
        else:
            title = selector.xpath('//*[@class="title"]/text()')[0]
    except Exception as exc:
        title = ""
    return title


def ahtv_get_pubtime(text):
    if not text:
        return ""
    else:
        # selector = etree.HTML(text)
        # pubtime = selector.xpath('//*[@class="data"]//text()')
        pubtime = "2020-" + text
        if pubtime:
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="article-time"]/text()')[0]
        return pubtime


def ahtv_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="f15a"]/text()')
        if not author:
            author = ""
        else:
            author = author[0]
        return author


def ahtv_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="theme-brief"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def ahtv_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def ctdsb_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@id="time"]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')[0]
        return pubtime


def ctdsb_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def ctdsb_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="content9"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def ctdsb_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="page-header"]/h3/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def jlntv_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="publish-time m-l-10"]/text()')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')[0]
        return pubtime


def jlntv_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="common-title m-b-10"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def jlntv_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="article-content"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def jlntv_get_author(text):
    if not text:
        return ""
    else:
        return ""


def daheapp_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="time"]/text()')
        if pubtime:
            pubtime = "2020-" + pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')[0]
        return pubtime


def daheapp_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def daheapp_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="textblock"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def daheapp_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="article-title"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def cztvcloud_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="time"]/text()')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="article-time"]/text()')[0]
        return pubtime


def cztvcloud_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@id="source"]/text()')
        if not author:
            author = ""
        else:
            author = author[0]
        return author


def cztvcloud_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="detailcontent"]//*')
        if not content:
            content = selector.xpath('//*[@class="theme-brief"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def cztvcloud_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="topTitle"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    title = title.replace("\n", "").replace("\t", "")
    return title


def qianfanapi_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="detail-title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    title = title.replace("\n", "").replace("\t", "")
    return title


def qianfanapi_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="content-div"]//*')
        if not content:
            content = selector.xpath('//*[@class="theme-brief"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def qianfanapi_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@id="source"]/text()')
        if not author:
            author = ""
        else:
            author = author[0]
        return author


def dachongfu_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@id="detail_time"]/@value')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')[0]
        return pubtime


def dachongfu_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="header-site"]/text()')
        if len(author) > 0:
            return author[0]
        return ""


def dachongfu_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="content-div"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def dachongfu_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="detail-title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def cfrtv_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="publish-time "]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="shareVideo_time"]/text()')[0]
            pubtime = pubtime.split(" |")[0]
            pubtime = timestamp_now_to(pubtime)
        return pubtime


def cfrtv_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def cfrtv_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="articleContent"]//div[2]/span//*')
        if not content:
            content = selector.xpath('//*[@id="articleContent"]//div[2]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def cfrtv_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="common-title m-b-10"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="shareVideo_title"]/text()')[0]
    return title


def tv0359_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//h2/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def tv0359_get_content(text):
    selector = etree.HTML(text)
    content = selector.xpath('//*[@class="conmm"]//*')
    content = photo_and_text(content)
    content_text = ""
    for e in content:
        content_text = content_text + e
    content_text = content_text.replace('\r', '')
    content_text = content_text.replace('\n', '')
    content_text = content_text.replace('\t', '')
    content_text = content_text.replace('\xa0', '')
    content_text = content_text.replace('\u3000', '')
    return content_text

def tv0359_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="data"]/text()')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = json.loads(text[0])
            time = jsonpath.jsonpath(pubtime,'$..time')
            if time:
                pubtime = pubtime[0]
            else:
                pubtime=""
        return pubtime


def foshannews_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="share-title"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="videoname"]/text()')[0]
    return title


def foshannews_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="TRS_Editor"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def foshannews_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="share-origin"]/time/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@id="logosite"]/span/text()')[0]
            pubtime = timestamp_now_to('20' + pubtime)
        return pubtime


def foshannews_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="share-origin"]/span/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def cnbksj_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="article-content"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        script = re.findall("function.*", content_text)
        for s in script:
            content_text = content_text.replace(s, "")
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def jin10_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="text"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def sogou_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="w-from"]/span[2]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="fl"]/text()')[0]
            pubtime = timestamp_now_to(pubtime)
        return pubtime


def sogou_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def sogou_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="articleContent"]//*')
        if not content:
            content = selector.xpath('//*[@class="box_con"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def sogou_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="articleTitle"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('/html/body/div[4]/h1/text()')[0]
    return title


def i2863wxshare_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="authorTt"]/span[2]/text()')
        if not author:
            author = ""
        return author


def i2863wxshare_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('/html/body//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def hebyun2_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="hender-info-over"]/span[0]/text()')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="article-time"]/text()')[0]
        return pubtime


def hebyun2_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="f15a"]/text()')
        if not author:
            author = ""
        else:
            author = author[0]
        return author


def hebyun2_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="articleContent"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-text-container fold-content"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def hebyun2_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="article-title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="news-basic"]/h1/text()')[0]
    return title


def jxxw2_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="time"]/text()')
        if pubtime:
            pubtime = pubtime[0].split(" |")[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@id="pubtime_baidu"]/text()')[0]
        return pubtime


def jxxw2_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="main"]//*')
        if not content:
            content = selector.xpath('//*[@id="Zoom"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def jxxw2_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')
        if not title:
            title = selector.xpath('//*[@class="BiaoTi"]/text()')
        title = title[0]
    return title


def sanlihe_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="theme-brief"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def dingxidaily_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*//time/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="shareVideo_time"]/text()')[0]
            pubtime = pubtime.split(" |")[0]
            pubtime = timestamp_now_to(pubtime)
        return pubtime


def dingxidaily_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def dingxidaily_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="content-show"]//p//*')
        if not content:
            content = selector.xpath('//*[@class="text"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def dingxidaily_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="ui-article-title"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="shareVideo_title"]/text()')[0]
    return title


def china_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="mArticle_Source"]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="shareVideo_time"]/text()')[0]
            pubtime = pubtime.split(" |")[0]
            pubtime = timestamp_now_to(pubtime)
        return pubtime


def china_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def china_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="mArticle_Content"]//*')
        if not content:
            content = selector.xpath('//*[@class="text"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def china_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="mArticle"]/h1/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="shareVideo_title"]/text()')[0]
    return title


def pcauto_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="u-date a-time"]/text()')
        if len(pubtime) > 0:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')
            if not pubtime:
                pubtime = selector.xpath('//*[@class="pubTime"]/text()')
            if not pubtime:
                pubtime = selector.xpath('//*[@class="cmtList-detail"]/@data-time')
            pubtime = timestamp_now_to(pubtime[0])
        return pubtime


def pcauto_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="author-nickname"]/text()')
        if author:
            author = author[0]
        else:
            author = ""
        return author


def pcauto_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="JartCon"]//*')
        if not content:
            content = selector.xpath('//*[@id="js_content"]//*')
        if not content:
            content = selector.xpath('//*[@class="artText clearfix"]//*')
        if not content:
            content = selector.xpath('//*[@class="txt"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def pcauto_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="m-art-title"]/text()')
    if title:
        title = title[0]
        title = title.replace("\n", "")
    else:
        title = selector.xpath('//*[@class="tit"]/text()')
        if not title:
            title = selector.xpath('//*[@class ="title"]/text()')
        if not title:
            title = selector.xpath('//*[@class="topic-title"]/text()')

        title = title[0]

    return title


def cyparty_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//html/body//*')
        if not content:
            content = selector.xpath('//*[@class="text"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def cqliving_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="detail_info_time"]/text()')
        if pubtime:
            pubtime = pubtime[0].replace(" ", "")
            pubtime = "2020-" + pubtime
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')[0]
        return pubtime


def cqliving_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="detail_content"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def cqliving_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="detail_title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def gdlwcloud_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="article-time"]/text()')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')[0]
        return pubtime


def gdlwcloud_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="article-title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def gdlwcloud_get_content(text):
    selector = etree.HTML(text)
    content = selector.xpath('//*[@id="articleContent"]//*')
    content = photo_and_text(content)
    content_text = ""
    for e in content:
        content_text = content_text + e
    content_text = content_text.replace('\r', '')
    content_text = content_text.replace('\n', '')
    content_text = content_text.replace('\t', '')
    content_text = content_text.replace('\xa0', '')
    content_text = content_text.replace('\u3000', '')
    return content_text


def jxxw3_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="data"]/text()')
        if pubtime:
            pubtime = pubtime.split(" |")[0]
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')[0]
        pub = pubtime.split("|")
        return pub[0].strip()


def jxxw3_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def jxxw3_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="main"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def jxxw4_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="data"]/text()')
        if pubtime:
            pubtime = pubtime.split(" |")[0]
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="time"]/text()')[0]
        pub = pubtime.split("|")
        return pub[0].strip()


def jxxw4_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="title"]/text()')[0]
    return title


def jxxw4_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@class="main"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def dxhmt_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="parentDiv"]//p/span/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def dxhmt_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="content"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def dxhmt_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@id="parentDiv"]//div/p[2]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')[0]
        return pubtime


def hebyun3_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@class="article-title"]/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="news-basic"]/h1/text()')[0]
    return title


def hebyun3_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="articleContent"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-text-container fold-content"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def hebyun3_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@class="hender-info-over"]/span[0]/text()')
        if pubtime:
            pubtime = timestamp_now_to(pubtime[0])
        else:
            pubtime = selector.xpath('//*[@class="article-time"]/text()')[0]
        return pubtime


def hebyun3_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="f15a"]/text()')
        if not author:
            author = ""
        else:
            author = author[0]
        return author


def dxhmt2_get_pubtime(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        pubtime = selector.xpath('//*[@id="parentDiv"]//div/p[2]/text()')
        if pubtime:
            pubtime = pubtime[0]
            pubtime = timestamp_now_to(pubtime)
        else:
            pubtime = selector.xpath('//*[@class="news-subtitle"]/p[2]/text()')[0]
        return pubtime


def dxhmt2_get_title(text):
    selector = etree.HTML(text)
    title = selector.xpath('//*[@id="parentDiv"]//p/span/text()')
    if title:
        title = title[0]
    else:
        title = selector.xpath('//*[@class="news-title"]/text()')
    return title


def dxhmt2_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@id="content"]//*')
        if not content:
            content = selector.xpath('//*[@class="main-aticle"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def cfrtv2_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*')
        if not content:
            content = selector.xpath('//*[@class="article-content"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text


def i2863_3_get_author(text):
    if not text:
        return ""
    else:
        selector = etree.HTML(text)
        author = selector.xpath('//*[@class="authorTt"]/span[2]/text()')
        if not author:
            author = ""
        return author


def i2863_3_get_content(text):
    if text:
        selector = etree.HTML(text)
        content = selector.xpath('//*[@powered-by="xiumi.us"]//*')
        if len(content) < 10:
            content = selector.xpath('//div[@class="mainCons"]//*')
        content = photo_and_text(content)
        content_text = ""
        for e in content:
            content_text = content_text + e
        content_text = content_text.replace('\r', '')
        content_text = content_text.replace('\n', '')
        content_text = content_text.replace('\t', '')
        content_text = content_text.replace('\xa0', '')
        content_text = content_text.replace('\u3000', '')
        content_text = content_text.replace('                                                ', '')
    else:
        content_text = ""
    return content_text
